<template>
	<view class="content">
		<view style="text-align: center;font-size: 32rpx;font-weight: bold;margin-bottom: 20rpx;">
			{{form.institutionName}}
		</view>
		<view class="margin-bottom:30rpx">
			<u-parse :content="form.introduction"></u-parse>
		</view>
		<u-gap height="1" bgColor="#bbb"></u-gap>
		<view class="review">
			<view class="review-top">
				<view class="review-left">
					用户评价（256）
				</view>
				<view class="review-right">
					查看更多>
				</view>
			</view>
			<view class="review-list">
				<uni-icons type="contact-filled" size="50"></uni-icons>
				<view class="review-list-right">
					<view class="review-list-tit">
						用户100000
					</view>
					<view class="review-list-time">
						2024-03-25 11：56：44
					</view>
					<view class="review-list-rate">
						<view class="">
							评分
						</view>
						<uni-rate size="18" :readonly="true" :value="4" />
						<view class="">
							4
						</view>
					</view>
					<view class="review-list-content">
						莲湖区环城西路社区卫生服务中心现代化、人性化、多元化。
					</view>
					<view class="review-list-img">
						<uni-icons type="image-filled" size="80"></uni-icons>
					</view>
				</view>
			</view>
			<view style="display: flex;justify-content: space-around;gap: 100rpx; padding: 50rpx;">
				<u-button @click="publish()" type="primary" size="mini" text="发表评论"></u-button>
				<u-button @click="makePhoneCall(form.adminPhone)" type="success" size="mini" text="电话咨询"></u-button>
			</view>
		</view>
		<u-popup :show="show" mode="top">
			<view style="height: 1200rpx;padding: 30rpx;display: flex;flex-direction: column;gap: 20rpx;">
				<view style="display: flex;justify-content: space-between;">
					<text @click="show=false">关闭</text>
					<text style="color: #0075b0;">发布</text>
				</view>
				<view class="review-list-rate">
					<view class="">
						评分
					</view>
					<uni-rate size="18" v-model="publishForm.rate" />
					<view class="">
						{{publishForm.rate}}
					</view>
				</view>
				<u--textarea v-model="publishForm.content" placeholder="请输入内容" count></u--textarea>
				<text>上传图片</text>
				<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" multiple name="6"
					:maxCount="1">
					<image src="../../../static/feixiang/evaluate/uploadpic@2x.png" mode="widthFix"
						style="width: 212rpx;height: 212rpx;margin-top: 16rpx;"></image>
				</u-upload>
			</view>

		</u-popup>
	</view>
</template>

<script>
	import {
		queryByUid
	} from '../../common/api/medicalMaintenance.js'
	export default {
		data() {
			return {
				show: false,
				publishForm: {
					rate: 0,
					content: '',
					img: ''
				},
				fileList: [],
				form: {}
			}
		},
		onLoad(e) {
			this.uid = e.institutionUid
			this.getData()
		},
		methods: {
			getData() {
				let param = {
					uid: this.uid
				}
				queryByUid(param).then(res => {
					this.form = res.data.data
				}).catch(err => {
					console.log(err)
				});
			},
			makePhoneCall(data) {
				uni.makePhoneCall({
					phoneNumber: data //仅为示例
				});
			},
			publish() {
				this.show = true
			},
			async afterRead1(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				// this.model1.userInfo.yibaoImage
				// this.model1.userInfo.casesImage
				let fileListLen = this[`fileList`].length
				lists.map((item) => {
					this[`fileList`].push({
						...item,
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList`][fileListLen]
					this[`fileList`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://applet.youtuyiliao.com/upload/public/uploadImage', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							this.publishForm.img = JSON.parse(res.data).data
						}
					});
				})
			},
			deletePic(event) {
				this.publishForm.img.splice(event.index, 1)
			},
		}
	}
</script>

<style scoped>
	.content {
		padding: 30rpx;
	}

	.review {
		padding: 40rpx 0;
	}

	.review-top {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}

	.review-list {
		display: flex;
		gap: 20rpx;
	}

	.review-list-right {
		display: flex;
		flex-direction: column;
		gap: 10rpx;
	}

	.review-list-tit {
		font-weight: bold;
	}

	.review-list-time {
		font-size: 24rpx;
		color: #999;
	}

	.review-list-rate {
		display: flex;
		align-items: center;
		gap: 10rpx;
	}
</style>